﻿using Lidgren.Network;
using System;

namespace BattleFury.Lib.Network.Packets
{
    [Serializable]
    public class LoginPacket : IPacket
    {
        PacketCommand IPacket.Command { get { return PacketCommand.Login; } }
        NetDeliveryMethod IPacket.NetDeliveryMethod { get { return NetDeliveryMethod.ReliableOrdered; } }
        long IPacket.ServerTime
        {
            get { return _servertime; }
        }

        private long _servertime;

        public string Name { get; set; }
        public string Password { get; set; }
        public LoginPacket(long ServerTime)
        { _servertime = ServerTime; }

        public LoginPacket(long ServerTime, NetIncomingMessage msg)
        {
            _servertime = ServerTime;
            Name = msg.ReadString();
            Password = msg.ReadString();
        }

        NetOutgoingMessage IPacket.ToOutgoingMessage(NetClient client)
        {
            NetOutgoingMessage msg = client.CreateMessage();
            msg.Write((int)((IPacket)this).Command);
            msg.Write(Name);
            msg.Write(Password);
            return msg;
        }
    }
}